package com.ray.basic;

import com.google.common.collect.Ordering;
import lombok.Data;

import java.util.Comparator;

/**
 * 类似于排序
 * 比较一下和comparator的优劣
 * 这个博客说得好。
 * https://blog.csdn.net/u012881904/article/details/79280059
 * @author Ray
 */
public class C13Order {
    public static void main(String[] args) {

        TestClass01 classToCompare = new TestClass01();
        classToCompare.getField1();

        Comparator<TestClass01> comparator1 = new Comparator<TestClass01>() {
            @Override
            public int compare(TestClass01 left, TestClass01 right) {
                return left.getField1() - right.getField1();
            }
        };

        // comparator可以用非常简单的lambda, 这种情况没必要使用ording, 用lambda就很简单了。
        Comparator<TestClass01> comparator2 = (left, right) -> left.getField1() - right.getField1();

        Ordering<TestClass01> ordering = new Ordering<TestClass01>() {
            @Override
            public int compare(TestClass01 left, TestClass01 right) {
                return left.getField1() - right.getField1();
            }
        };

        Ordering<TestClass01> ordering1 = Ordering.from(comparator1);

//        Ordering.natural().compare()

    }

}

@Data
class TestClass01 {
    private int field1;
    private int field2;
}
